<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\GkyUserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Gky Users';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="gky-user-index">


    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <div class="col-md-12">      
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12">{input}</div>',
                    ]
                ])
        ?>

        <div class="col-md-10">
            <label style="float: left;margin-top: 5px;">教师姓名</label>
            <div style="overflow: hidden;">
                <?php
//                $data = app\models\GkyUser::find()->all();
//                echo $form->field($searchModel, 'username')->widget(Select2::classname(), [
//                    'data' => ArrayHelper::map($data, 'username', 'username'),
//                    'options' => ['placeholder' => '请输入内容'],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],
//                ]);
                ?>
                 
                 <?php
                $projects = app\models\GkyUser::find()->all();
                foreach ($projects as $item) {
                    $source[] = $item->username;
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'username',
                    'options'=>['style'=>'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>  
            </div>
        </div>




        <div class="col-md-2 text-center">
            <?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?> 
        </div>

    </div>

    <div class="col-md-12 text-right" style="margin: 15px 0 15px 15px;">
    </div>

    <?php ActiveForm::end(); ?>    
    <?php Pjax::begin(); ?>
    <?=
    GridView::widget([
        'tableOptions' => ['class' => 'table table-bordered'],
        'rowOptions' => [
            'style' => '
                        border-bottom: 18px solid #EFEFEF;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        height: 50px;
                        '],
        'headerRowOptions' => [
            'style' => 'font-size: 15px;color: #2a70e9;background-color: #D9EDF7;',
        ],
        'layout' => "{items}\n{pager}",
        'dataProvider' => $dataProvider,
        'columns' => [
            // ['class' => 'yii\grid\SerialColumn'],
            // 'id',
            'username',
            'email',
            // 'password_hash',
            // 'auth_key',
            // 'confirmed_at',
            // 'unconfirmed_email:email',
            // 'blocked_at',
            // 'registration_ip',
            // 'created_at',
            // 'updated_at',
            // 'flags',
            // 'parentserverid',
            [
                'class' => 'yii\grid\ActionColumn',
                'urlCreator' => function($action, $model, $key, $index) {
                    return \yii\helpers\Url::toRoute(['gky-profile/view', 'id' => $key]);
                },
                        'template' => '{view}',
                        'buttons' => [
                            //view button
                            'view' => function ($url) {
                                return Html::a('<span class="fa fa-search"></span>详细', $url, [
                                            'title' => Yii::t('app', 'View'),
//                                    'class' => 'btn btn-primary btn-xs',
                                ]);
                            },
                                ],
                            ],
                        ],
                    ]);
                    ?>
                    <?php Pjax::end(); ?>
</div>
<script>

    var global_Html = "";
    function printme() {
        global_Html = document.body.innerHTML;
        document.body.innerHTML = $('#tableContainer').html();
        $('.btn').hide();
        $('.pagination').hide();
        $('a').each(function () {
            $(this).replaceWith($(this).html());
        });
        window.print();
        window.setTimeout(function () {
            document.body.innerHTML = global_Html;
        }, 300);
    }

</script>